home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / Demos / AirHockey / selectDevice.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2001-10-08  |  10.4 KB  |  325 lines

  1. VERSION 5.00
  2. Begin VB.Form frmSelectDevice 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Select Device"
  5.    ClientHeight    =   2805
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   6045
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   2805
  13.    ScaleWidth      =   6045
  14.    ShowInTaskbar   =   0   'False
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.Frame optRenderingModeoptRenderingMode 
  17.       Caption         =   "Rendering Mode"
  18.       Height          =   1335
  19.       Left            =   120
  20.       TabIndex        =   7
  21.       Top             =   1320
  22.       Width           =   4575
  23.       Begin VB.ComboBox cboFullScreenMode 
  24.          Enabled         =   0   'False
  25.          Height          =   315
  26.          Left            =   2040
  27.          Style           =   2  'Dropdown List
  28.          TabIndex        =   10
  29.          Top             =   720
  30.          Width           =   2295
  31.       End
  32.       Begin VB.OptionButton optRenderingMode 
  33.          Caption         =   "&Fullscreen mode"
  34.          Height          =   375
  35.          Index           =   1
  36.          Left            =   240
  37.          TabIndex        =   9
  38.          Top             =   690
  39.          Width           =   1455
  40.       End
  41.       Begin VB.OptionButton optRenderingMode 
  42.          Caption         =   "Use desktop &window"
  43.          Height          =   375
  44.          Index           =   0
  45.          Left            =   240
  46.          TabIndex        =   8
  47.          Top             =   240
  48.          Value           =   -1  'True
  49.          Width           =   1815
  50.       End
  51.    End
  52.    Begin VB.CommandButton cmdCancel 
  53.       Cancel          =   -1  'True
  54.       Caption         =   "Cancel"
  55.       Height          =   375
  56.       Left            =   4800
  57.       TabIndex        =   4
  58.       Top             =   720
  59.       Width           =   1095
  60.    End
  61.    Begin VB.CommandButton cmdOk 
  62.       Caption         =   "OK"
  63.       Default         =   -1  'True
  64.       Height          =   375
  65.       Left            =   4800
  66.       TabIndex        =   3
  67.       Top             =   240
  68.       Width           =   1095
  69.    End
  70.    Begin VB.Frame Frame1 
  71.       Caption         =   "Rendering device"
  72.       Height          =   1095
  73.       Left            =   120
  74.       TabIndex        =   0
  75.       Top             =   120
  76.       Width           =   4575
  77.       Begin VB.ComboBox cboDevice 
  78.          Height          =   315
  79.          Left            =   1440
  80.          Style           =   2  'Dropdown List
  81.          TabIndex        =   6
  82.          Top             =   600
  83.          Width           =   2775
  84.       End
  85.       Begin VB.ComboBox cboAdapter 
  86.          Height          =   315
  87.          Left            =   1440
  88.          Style           =   2  'Dropdown List
  89.          TabIndex        =   2
  90.          Top             =   240
  91.          Width           =   2775
  92.       End
  93.       Begin VB.Label Label2 
  94.          AutoSize        =   -1  'True
  95.          Caption         =   "D3D &device:"
  96.          Height          =   195
  97.          Left            =   360
  98.          TabIndex        =   5
  99.          Top             =   660
  100.          Width           =   900
  101.       End
  102.       Begin VB.Label Label1 
  103.          AutoSize        =   -1  'True
  104.          Caption         =   "&Adapter:"
  105.          Height          =   195
  106.          Left            =   360
  107.          TabIndex        =   1
  108.          Top             =   300
  109.          Width           =   600
  110.       End
  111.    End
  112. Attribute VB_Name = "frmSelectDevice"
  113. Attribute VB_GlobalNameSpace = False
  114. Attribute VB_Creatable = False
  115. Attribute VB_PredeclaredId = True
  116. Attribute VB_Exposed = False
  117. Option Explicit
  118. Dim m_callback As Object
  119. Public Sub SelectDevice(callback As Object)
  120.     If callback Is Nothing Then Exit Sub
  121.     Set m_callback = callback
  122.     Dim dm As D3DDISPLAYMODE
  123.     If g_d3dpp.Windowed = 0 Then
  124.         m_callback.InvalidateDeviceObjects
  125.         D3DUtil_ResetWindowed
  126.         m_callback.RestoreDeviceObjects
  127.         
  128.     End If
  129.     Me.Show 1
  130.     Set m_callback = Nothing
  131. End Sub
  132. Private Sub cboAdapter_Click()
  133.     Dim devtype As CONST_D3DDEVTYPE
  134.       
  135.     If (cboDevice.ListIndex = 1) Then
  136.         devtype = D3DDEVTYPE_REF
  137.     Else
  138.         devtype = D3DDEVTYPE_HAL
  139.     End If
  140.        
  141.     Call UpdateModes(cboAdapter.ListIndex, devtype)
  142. End Sub
  143. Private Sub cboDevice_Change()
  144.     Dim devtype As CONST_D3DDEVTYPE
  145.     If (cboDevice.ListIndex = 1) Then
  146.         devtype = D3DDEVTYPE_REF
  147.     Else
  148.         devtype = D3DDEVTYPE_HAL
  149.     End If
  150.        
  151.     Call UpdateModes(cboAdapter.ListIndex, devtype)
  152. End Sub
  153. Private Sub cmdCancel_Click()
  154.     Set m_callback = Nothing
  155.     Me.Hide
  156. End Sub
  157. Public Sub UpdateNow(callback As Object)
  158.     On Local Error Resume Next
  159.     Dim bAdapterChanged As Boolean
  160.     Dim bRasterizerChanged As Boolean
  161.     Dim bRef As Boolean
  162.     Dim lWindowed As Long
  163.     Dim AdapterID As Long
  164.     Dim ModeID As Long
  165.     Dim devtype As CONST_D3DDEVTYPE
  166.     If callback Is Nothing Then Exit Sub
  167.     Set m_callback = callback
  168.     AdapterID = cboAdapter.ListIndex
  169.     ModeID = cboFullScreenMode.ListIndex
  170.         
  171.     ' see if user changed adapters
  172.     If g_lCurrentAdapter <> AdapterID Then bAdapterChanged = True
  173.                 
  174.     bRef = g_Adapters(g_lCurrentAdapter).bReference
  175.         
  176.     If (cboDevice.ListIndex = 1) Then
  177.         devtype = D3DDEVTYPE_REF
  178.     Else
  179.         devtype = D3DDEVTYPE_HAL
  180.     End If
  181.     ' see if user changed rasterizers
  182.     If (devtype = D3DDEVTYPE_REF And bRef = False) Then bRasterizerChanged = True
  183.     If (devtype = D3DDEVTYPE_HAL And bRef = True) Then bRasterizerChanged = True
  184.     If optRenderingMode(1).Value = True Then
  185.         lWindowed = 0
  186.     Else
  187.         lWindowed = 1
  188.     End If
  189.         
  190.     ' if they didnt change adapters or switch to refrast, then we can just use reset
  191.     If bAdapterChanged = False And bRasterizerChanged = False Then
  192.                 
  193.         'If trying to go Fullscreen
  194.         If lWindowed = 0 Then
  195.         
  196.             'call g_dev.reset
  197.             Call D3DUtil_ResizeFullscreen(g_focushwnd, cboFullScreenMode.ListIndex)
  198.         
  199.         Else
  200.             
  201.             Call D3DUtil_ResizeWindowed(g_focushwnd)
  202.         
  203.         End If
  204.         
  205.         'tell user needs to restore device objects
  206.         m_callback.RestoreDeviceObjects
  207.         
  208.         'exit modal dialog
  209.         Unload Me
  210.         Exit Sub
  211.     End If
  212.     Set g_dev = Nothing
  213.     D3DUtil_ReleaseAllTexturesFromPool
  214.     'tell user to lose reference counts in its objects device objects
  215.     m_callback.InvalidateDeviceObjects
  216.     m_callback.DeleteDeviceObjects
  217.     'Reinitialize D3D
  218.     If lWindowed = 0 Then
  219.         D3DUtil_InitFullscreen g_focushwnd, AdapterID, ModeID, devtype, True
  220.     Else
  221.         D3DUtil_InitWindowed g_focushwnd, AdapterID, devtype, True
  222.     End If
  223.         
  224.     'tell user to re-create device objects
  225.     m_callback.InitDeviceObjects
  226.     'tell user to restore device objects
  227.     m_callback.RestoreDeviceObjects
  228.     'exit modal dialog
  229.     Unload Me
  230. End Sub
  231. Private Sub cmdOk_Click()
  232.     Set m_callback = Nothing
  233.     Me.Hide
  234. End Sub
  235. Private Sub Form_Load()
  236.         
  237.     Call UpdateAdapters
  238.     Call UpdateDevices(g_lCurrentAdapter)
  239.     Call UpdateModes(g_lCurrentAdapter, g_Adapters(g_lCurrentAdapter).DeviceType)
  240. End Sub
  241. Private Sub UpdateAdapters()
  242.     Dim i As Long
  243.     Dim sDescription As String
  244.     cboAdapter.Clear
  245.         
  246.     For i = 0 To g_lNumAdapters - 1
  247.         sDescription = vbNullString
  248.         sDescription = StrConv(g_Adapters(i).d3dai.Description, vbUnicode)
  249.         cboAdapter.AddItem sDescription
  250.     Next
  251.     cboAdapter.ListIndex = g_lCurrentAdapter
  252. End Sub
  253. Private Sub UpdateDevices(Adapter As Long)
  254.     Dim i As Long
  255.     cboDevice.Clear
  256.     cboDevice.AddItem "HAL"
  257.     cboDevice.AddItem "REF"
  258.     'If g_Adapters(g_lCurrentAdapter).bReference Then
  259.     If g_Adapters(Adapter).bReference Then
  260.         cboDevice.ListIndex = 1
  261.     Else
  262.         cboDevice.ListIndex = 0
  263.     End If
  264. End Sub
  265. Private Sub UpdateModes(Adapter As Long, devtype As CONST_D3DDEVTYPE)
  266.     Dim i As Long
  267.     Dim pAdapter As D3DUTIL_ADAPTERINFO
  268.     Dim sModeString As String
  269.     cboFullScreenMode.Clear
  270.             
  271.     With g_Adapters(Adapter).DevTypeInfo(devtype)
  272.         For i = 0 To .lNumModes - 1
  273.             sModeString = .Modes(i).lWidth & " x "
  274.             sModeString = sModeString & .Modes(i).lHeight & " x "
  275.             If .Modes(i).format = D3DFMT_X8R8G8B8 Or _
  276.                 .Modes(i).format = D3DFMT_A8R8G8B8 Or _
  277.                 .Modes(i).format = D3DFMT_R8G8B8 Then
  278.                 sModeString = sModeString & "32"
  279.             Else
  280.                 sModeString = sModeString & "16"
  281.             End If
  282.             
  283.             cboFullScreenMode.AddItem sModeString
  284.         Next
  285.         If cboFullScreenMode.ListCount > 0 Then cboFullScreenMode.ListIndex = .lCurrentMode
  286.     End With
  287.                 
  288. End Sub
  289. Private Sub optRenderingMode_Click(Index As Integer)
  290.     If Index = 1 Then
  291.         cboFullScreenMode.Enabled = True
  292.     Else
  293.         cboFullScreenMode.Enabled = False
  294.     End If
  295. End Sub
  296. Public Property Get Windowed() As Boolean
  297.     Windowed = optRenderingMode(0).Value
  298. End Property
  299. Public Property Get AdapterString() As String
  300.     AdapterString = cboAdapter.List(cboAdapter.ListIndex)
  301. End Property
  302. Public Property Get Adapter() As Long
  303.     Adapter = cboAdapter.ListIndex
  304. End Property
  305. Public Property Get ModeString() As String
  306.     ModeString = cboFullScreenMode.List(cboFullScreenMode.ListIndex)
  307. End Property
  308. Public Property Get Mode() As Long
  309.     Mode = cboFullScreenMode.ListIndex
  310. End Property
  311. Public Property Let Mode(ByVal lMode As Long)
  312.     On Error Resume Next 'Just in case
  313.     cboFullScreenMode.ListIndex = lMode
  314. End Property
  315. Public Property Let Adapter(ByVal lAdapter As Long)
  316.     cboAdapter.ListIndex = lAdapter
  317. End Property
  318. Public Property Let Windowed(ByVal fWindow As Boolean)
  319.     If fWindow Then
  320.         optRenderingMode(0).Value = True
  321.     Else
  322.         optRenderingMode(1).Value = True
  323.     End If
  324. End Property
  325.